//
//  NoticeListModel.m
//
//  Created by mac  on 2018/12/5
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "NoticeListModel.h"


NSString *const kNoticeListModelBusinessDataDesc = @"BusinessDataDesc";
NSString *const kNoticeListModelReadFlag = @"ReadFlag";
NSString *const kNoticeListModelIssueDate = @"IssueDate";
NSString *const kNoticeListModelBusinessDataID = @"BusinessDataID";
NSString *const kNoticeListModelExtraData = @"ExtraData";
NSString *const kNoticeListModelTitle = @"Title";
NSString *const kNoticeListModelNotifyType = @"NotifyType";
NSString *const kNoticeListModelBusinessType = @"BusinessType";
NSString *const kNoticeListModelID = @"ID";


@interface NoticeListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation NoticeListModel

@synthesize businessDataDesc = _businessDataDesc;
@synthesize readFlag = _readFlag;
@synthesize issueDate = _issueDate;
@synthesize businessDataID = _businessDataID;
@synthesize extraData = _extraData;
@synthesize title = _title;
@synthesize notifyType = _notifyType;
@synthesize businessType = _businessType;
@synthesize iDProperty = _iDProperty;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.businessDataDesc = [self objectOrNilForKey:kNoticeListModelBusinessDataDesc fromDictionary:dict];
            self.readFlag = [[self objectOrNilForKey:kNoticeListModelReadFlag fromDictionary:dict] doubleValue];
            self.issueDate = [self objectOrNilForKey:kNoticeListModelIssueDate fromDictionary:dict];
            self.businessDataID = [[self objectOrNilForKey:kNoticeListModelBusinessDataID fromDictionary:dict] doubleValue];
            self.extraData = [self objectOrNilForKey:kNoticeListModelExtraData fromDictionary:dict];
            self.title = [self objectOrNilForKey:kNoticeListModelTitle fromDictionary:dict];
            self.notifyType = [[self objectOrNilForKey:kNoticeListModelNotifyType fromDictionary:dict] doubleValue];
            self.businessType = [[self objectOrNilForKey:kNoticeListModelBusinessType fromDictionary:dict] doubleValue];
            self.iDProperty = [[self objectOrNilForKey:kNoticeListModelID fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.businessDataDesc forKey:kNoticeListModelBusinessDataDesc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.readFlag] forKey:kNoticeListModelReadFlag];
    [mutableDict setValue:self.issueDate forKey:kNoticeListModelIssueDate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.businessDataID] forKey:kNoticeListModelBusinessDataID];
    [mutableDict setValue:self.extraData forKey:kNoticeListModelExtraData];
    [mutableDict setValue:self.title forKey:kNoticeListModelTitle];
    [mutableDict setValue:[NSNumber numberWithDouble:self.notifyType] forKey:kNoticeListModelNotifyType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.businessType] forKey:kNoticeListModelBusinessType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.iDProperty] forKey:kNoticeListModelID];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.businessDataDesc = [aDecoder decodeObjectForKey:kNoticeListModelBusinessDataDesc];
    self.readFlag = [aDecoder decodeDoubleForKey:kNoticeListModelReadFlag];
    self.issueDate = [aDecoder decodeObjectForKey:kNoticeListModelIssueDate];
    self.businessDataID = [aDecoder decodeDoubleForKey:kNoticeListModelBusinessDataID];
    self.extraData = [aDecoder decodeObjectForKey:kNoticeListModelExtraData];
    self.title = [aDecoder decodeObjectForKey:kNoticeListModelTitle];
    self.notifyType = [aDecoder decodeDoubleForKey:kNoticeListModelNotifyType];
    self.businessType = [aDecoder decodeDoubleForKey:kNoticeListModelBusinessType];
    self.iDProperty = [aDecoder decodeDoubleForKey:kNoticeListModelID];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_businessDataDesc forKey:kNoticeListModelBusinessDataDesc];
    [aCoder encodeDouble:_readFlag forKey:kNoticeListModelReadFlag];
    [aCoder encodeObject:_issueDate forKey:kNoticeListModelIssueDate];
    [aCoder encodeDouble:_businessDataID forKey:kNoticeListModelBusinessDataID];
    [aCoder encodeObject:_extraData forKey:kNoticeListModelExtraData];
    [aCoder encodeObject:_title forKey:kNoticeListModelTitle];
    [aCoder encodeDouble:_notifyType forKey:kNoticeListModelNotifyType];
    [aCoder encodeDouble:_businessType forKey:kNoticeListModelBusinessType];
    [aCoder encodeDouble:_iDProperty forKey:kNoticeListModelID];
}

- (id)copyWithZone:(NSZone *)zone
{
    NoticeListModel *copy = [[NoticeListModel alloc] init];
    
    if (copy) {

        copy.businessDataDesc = [self.businessDataDesc copyWithZone:zone];
        copy.readFlag = self.readFlag;
        copy.issueDate = [self.issueDate copyWithZone:zone];
        copy.businessDataID = self.businessDataID;
        copy.extraData = [self.extraData copyWithZone:zone];
        copy.title = [self.title copyWithZone:zone];
        copy.notifyType = self.notifyType;
        copy.businessType = self.businessType;
        copy.iDProperty = self.iDProperty;
    }
    
    return copy;
}


@end
